﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace FizzBuzzCore
{
    /// <summary>
    /// Helper class that contains the FizzBuzz logic
    /// </summary>
    public static class FizzBuzzLogic
    {
        /// <summary>
        /// Returns a string list with a range from the lower limit to the upper limit. 
        /// Replaces numbers divisible by 3 and 5 with FizzBuzz, numbers divisible by 3 only with Fizz and numbers divisible by 5 only with Buzz
        /// </summary>
        /// <param name="lowerLimit">Lower Limit</param>
        /// <param name="upperLimit">Upper Limit</param>
        /// <returns>the FizzBuzz sequence</returns>
        public static IList<string> GetFizzBuzzSequence(short lowerLimit, short upperLimit)
        {
            if (lowerLimit > upperLimit)
            {
                throw new ApplicationException(FizzBuzzResource.rangeExceptionText);
            }

            IList<string> fizzBuzzList = new List<string>();

            for (var index = lowerLimit; index <= upperLimit; index++)
            {
                if (index % 3 == 0 || index % 5 == 0)
                {
                    string outputText = string.Empty;
                    if (index % 3 == 0)
                    {
                        outputText = FizzBuzzResource.fizzText;
                    }
                    if (index % 5 == 0)
                    {
                        outputText += FizzBuzzResource.buzzText;
                    }
                    fizzBuzzList.Add(outputText);
                }
                else
                {
                    fizzBuzzList.Add(index.ToString(CultureInfo.InvariantCulture));
                }
            }
            return fizzBuzzList;
        }
    }
}
